/**
 * 版权所有（c）2021. 上海海鼎信息工程股份有限公司，保留所有权利
 */
package com.lovely602.design.behavior.mediator.demo;

import java.util.ArrayList;
import java.util.List;

/**
 * 简单单例中介者
 *
 * @author lizhixing
 */
public class SimpleMediator {

  private static final SimpleMediator smd = new SimpleMediator();
  private final List<SimpleColleague> colleagues = new ArrayList<>();

  private SimpleMediator() {
  }

  public static SimpleMediator getMedium() {
    return (smd);
  }

  public void register(SimpleColleague colleague) {
    if (!colleagues.contains(colleague)) {
      colleagues.add(colleague);
    }
  }

  public void relay(SimpleColleague scl) {
    for (SimpleColleague ob : colleagues) {
      if (!ob.equals(scl)) {
        ((SimpleColleague) ob).receive();
      }
    }
  }

}
